<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="Title" prop="createTime">
        <el-input
          style="width: 200px;"
          v-model="queryParams.title"
          placeholder=""
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Salary" prop="salary">
        <el-input
          style="width: 100px;margin-right: 10px;"
          v-model="queryParams.minSalary"
          placeholder="From"
          clearable
          @keyup.enter.native="handleQuery"
        />
        <span>-</span>
        <el-input
          style="width: 100px;margin-left: 10px;"
          v-model="queryParams.maxSalary"
          placeholder="To"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">Search</el-button>
        <el-button v-if="false" icon="el-icon-refresh" size="mini" @click="resetQuery">Reset</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="primary"-->
          <!--plain-->
          <!--icon="el-icon-plus"-->
          <!--size="mini"-->
          <!--@click="handleAdd"-->
        <!--&gt;新增</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="success"-->
      <!--plain-->
      <!--icon="el-icon-edit"-->
      <!--size="mini"-->
      <!--:disabled="single"-->
      <!--@click="handleUpdate"-->
      <!--&gt;修改</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="danger"-->
      <!--plain-->
      <!--icon="el-icon-delete"-->
      <!--size="mini"-->
      <!--:disabled="multiple"-->
      <!--@click="handleDelete"-->
      <!--&gt;删除</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="warning"-->
          <!--plain-->
          <!--icon="el-icon-download"-->
          <!--size="mini"-->
          <!--@click="handleExport"-->
          <!--v-hasPermi="['system:position:export']"-->
        <!--&gt;导出</el-button>-->
      <!--</el-col>-->
      <!--<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table
      border
      v-loading="loading"
      :data="positionList"
      @selection-change="handleSelectionChange">
      <el-table-column
        label="Action"
        width="80px"
        align="left"
        class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-edit"-->
            <!--@click="handleUpdate(scope.row)"-->
          <!--&gt;edit</el-button>-->
          <!--<br>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleInterview(scope.row)"
          >interview</el-button>
          <br />
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleNote(scope.row)"
          >note</el-button>
          <!--<el-button-->
          <!--size="mini"-->
          <!--type="text"-->
          <!--icon="el-icon-delete"-->
          <!--@click="handleDelete(scope.row)"-->
          <!--&gt;删除</el-button>-->
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="Title"
        align="left"
        prop="title" />
      <el-table-column
        show-overflow-tooltip
        label="Salary"
        align="left"
        prop="salary" />
      <el-table-column
        show-overflow-tooltip
        label="Salary Cap"
        align="left"
        prop="salaryupper" />
      <el-table-column
        show-overflow-tooltip
        label="Report To"
        align="left"
        prop="reportTo" />
      <el-table-column
        show-overflow-tooltip
        label="Education"
        align="left"
        prop="education" />
      <el-table-column
        show-overflow-tooltip
        label="Assignment"
        align="left"
        prop="assignName" />
      <el-table-column
        show-overflow-tooltip
        label="Create Date"
        align="left"
        prop="createTime"
        width="100px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        width="120px"
        show-overflow-tooltip
        label="Position Closed"
        align="left"
        prop="closed">
        <template slot-scope="scope">
          <span v-if="scope.row.closed == 1">{{scope.row.remarks}}</span>
          <span v-else></span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { listAssignPosition, getPosition, delPosition, addPosition, updatePosition } from "@/api/system/position";

  export default {
    name: "Assignment",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        clientId: null,
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        positionList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          id: null,
          clientId: null,
          title: null,
          salary: null,
          minSalary: null,
          maxSalary: null,
          salaryupper: null,
          reportTo: null,
          education: null,
          jobDuties: null,
          specialReq: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          title: [
            { required: true, message: "$comment不能为空", trigger: "blur" }
          ],
        }
      };
    },
    created() {
      console.log("created");
      this.getList();
    },
    methods: {
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listAssignPosition(this.queryParams).then(response => {
          this.positionList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          createTime: null,
          createUserId: null,
          title: null,
          clientId: null,
          salary: null,
          salaryupper: null,
          reportTo: null,
          education: null,
          jobDuties: null,
          specialReq: null,
          bftal: null,
          bftmedical: null,
          bftdental: null,
          bftbonus: null,
          bftdblpay: null,
          bftcomss: null,
          bftother: null,
          remarks: null,
          closed: null,
          serial: null,
          posCode: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      handleNote(row) {
        this.$router.push({path:'/system/note/noteAdd',query: {id: null, clientId: row.clientId}})
      },
      /** 新增按钮操作 */
      handleAdd() {
        const obj = { path: "/system/position/positionAdd", name: "positionAdd" };
        this.$tab.closePage(obj);
        setTimeout(()=> {
          this.$router.push({path:'/system/position/positionAdd',query: {clientId: this.clientId}})
        }, 300);
      },
      handleInterview(row) {
        this.$router.push({path:'/system/interview/index',query: {id: row.id}})
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        const obj = { path: "/system/position/positionAdd", name: "positionAdd" };
        this.$tab.closePage(obj);
        setTimeout(()=> {
          this.$router.push({path:'/system/position/positionAdd',query: {id: row.id, clientId: row.clientId}})
        }, 300);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除？').then(function() {
          return delPosition(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/position/export', {
          ...this.queryParams
        }, `position_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
